XF.Bar = new function(){

	this.addBar = function(){
		XF.lightSideBar("addBar");
		var url  = global.contextPath + "/bar/add"
		$.ajax({
		  url: url,
		  type: "post",
		  data: {},
		  complete: function(xhr){
			  xhr = xhr['responseText'];
			  $("#barCenter").html(xhr);
		  }
		});
	};

	this.batchAddBar = function(){
		XF.lightSideBar("batchAddBar");
		var url  = global.contextPath + "/bar/batchAdd"
		$.ajax({
		  url: url,
		  type: "post",
		  data: {},
		  complete: function(xhr){
			  xhr = xhr['responseText'];
			  $("#barCenter").html(xhr);
		  }
		});
	};
	
	this.listBarSearch = function(orderByFieldReq){
		var orderByField = null;
		var orderByMode = null;
		var siteid = null;
		var brand = null;
		var deviceid = null;
		
		deviceid = $("input[name=deviceid]").val();
		siteid = $("select[name=siteid]").val();
		brand = $("select[name=brand]").val();
		
		if(typeof(orderByFieldReq)!='undefined' && orderByFieldReq!=""){
			orderByField = orderByFieldReq;
			var td = $("th[orderByField="+orderByField+"]");
			orderByMode = td.find("span.px").attr("orderByMode");
		}

		 _bar_search(orderByField,orderByMode,siteid,brand,deviceid);
	};
	
	this.refreshAfterAddFaild = function(errorJson){
		if(typeof(errorJson)=="undefined")return;
		if(errorJson==null || errorJson=="")return;
		$("span[id*='errorTip']").hide();
		for(key in errorJson){
			var v = errorJson[key];
			var errorTip = $("#errorTip_"+key);
			errorTip.html(v);
			errorTip.show();
		}
	};
	
	this.deleteBar = function(id){
		$.messager.confirm('提示',"确认删除这条记录吗？",function(r){
		    if (r){
				var url  = global.contextPath + "/bar/doDelete"
				$.ajax({
				  url: url,
				  type: "post",
				  data: {id:id},
				  complete: function(xhr){
					  xhr = xhr['responseText'];
					  xhr = new Function("return " + xhr);
					  xhr = xhr();
					  xhr = xhr['status'];
					  if(xhr=="SUCCESS"){
						  $.messager.show({
							title:'提示',
							msg:'删除成功',
							timeout:3000,
							showType:'slide'
						  });
						  $(".userListWrap tr i[s="+id+"]").parent().parent().parent().remove();
					  }else if(xhr=="FAILD"){
						  $.messager.show({
							title:'提示',
							msg:'删除失败',
							timeout:5000,
							showType:'slide'
						  });
					  }
				   }
				});
		    }
		});
	};
	
	this.manageBar = function(){
		XF.lightSideBar('manageBar');
		_bar_search(null,null,null,null,null);
	};

    function _bar_search(orderByField,orderByMode,siteid,brand,deviceid){
        config.bar_search['args'] = [orderByField,orderByMode,siteid,brand,deviceid];
        SMT.xconfig.gvar.pageNum = '1';
        SMT.ajax(config.bar_search);
    }
	
}();

config.bar_search = {
		url: ""+global.contextPath+"/bar/manageList",
	    argsOrder: ['orderByField','orderByMode','siteid','brand','deviceid'],
	    needVar: true,
	    replaceExp: '#barCenter',
	    callBack: function() {
	    }		
};
